/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.raitcon.reports;

import com.raitcon.dao.Database;
import com.raitcon.hibernate.bean.Alumno;
import com.raitcon.hibernate.bean.Anio;
import com.raitcon.hibernate.db.AnioDB;
import com.raitcon.hibernate.db.GradoDB;
import com.raitcon.reports.common.AbstractReportBean;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import javax.annotation.PostConstruct;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;

import org.apache.log4j.Logger;

/**
 *
 * @author Mike
 */
@ManagedBean(name ="reportNotaBean")
@ViewScoped
public class ReportNotaBean extends  AbstractReportBean  implements Serializable  {
    
    protected static Logger log = Logger.getLogger(ReportNotaBean.class); 
    private static  final  long serialVersionUID=-2377612760546575078L; 
    
    private static final int DECIMALS = 1;
    private static final int CLIENT_ROWS_IN_AJAX_MODE = 15;
    private static final int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP;
    private String dniAlumno;
    private String apellNombres;
    private int idGrado;
    private String strAbreviaturaGrado;
    private int idAnio;
    private String strDescAnio;
    private Anio anio;
    private Alumno alumno;
    private String msg;
    //nombre reporte
    private final String COMPILE_FILE_NAME = "libretaPrimerGrado";
       
    @PostConstruct
    public void init(){
       log.info("Running init reporte notas");
    }

    /**
     * @return the dniAlumno
     */
    public String getDniAlumno() {
        return dniAlumno;
    }

    /**
     * @param dniAlumno the dniAlumno to set
     */
    public void setDniAlumno(String dniAlumno) {
        this.dniAlumno = dniAlumno;
    }

    /**
     * @return the idGrado
     */
    public int getIdGrado() {
        return idGrado;
    }

    /**
     * @param idGrado the idGrado to set
     */
    public void setIdGrado(int idGrado) {
        this.idGrado = idGrado;
    }

    /**
     * @return the idAnio
     */
    public int getIdAnio() {
        return idAnio;
    }

    /**
     * @param idAnio the idAnio to set
     */
    public void setIdAnio(int idAnio) {
        this.idAnio = idAnio;
    }

    /**
     * @return the apellNombres
     */
    public String getApellNombres() {
        return apellNombres;
    }

    /**
     * @param apellNombres the apellNombres to set
     */
    public void setApellNombres(String apellNombres) {
        this.apellNombres = apellNombres;
    }
  
    public void actualizarValores(){
        
          this.setDniAlumno(alumno.getDniAlumno());
          this.setApellNombres(alumno.getApellidoPaterno()+" "
                  +alumno.getApellidoMaterno()+" , "+alumno.getNombres());
    }

    /**
     * @return the alumno
     */
    public Alumno getAlumno() {
        return alumno;
    }

    /**
     * @param alumno the alumno to set
     */
    public void setAlumno(Alumno alumno) {
        this.alumno = alumno;
    }

    /**
     * @return the msg
     */
    public String getMsg() {
        return msg;
    }

    /**
     * @param msg the msg to set
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }
  
    

    @Override
    protected String getCompileFileName() {
       return COMPILE_FILE_NAME;
    }
    
    
     @Override
    protected Map<String, Object> getReportParameters() {
        Map<String, Object> reportParameters = new HashMap<String, Object>();
        AnioDB anioDB=new AnioDB();
        this.strDescAnio=anioDB.getAnioById(idAnio);
         GradoDB gradoDB=new GradoDB();
        this.setStrAbreviaturaGrado(gradoDB.getGradoById(idGrado));
        log.info("strDescAnio:"+strDescAnio);
        log.info("strAbreviaturaGrado:"+getStrAbreviaturaGrado());
        reportParameters.put("apell_name", apellNombres);
        reportParameters.put("anio", strDescAnio);
        reportParameters.put("grade_section", strAbreviaturaGrado+", \"A\"");
        reportParameters.put("directora", "Rosa De La Cruz Moreno");
        reportParameters.put("merito", "2°");
        reportParameters.put("mateI",new Long(12));
        reportParameters.put("mateII",new Long(9));
        reportParameters.put("mateIII",new Long(11));
        reportParameters.put("razonI",new Long(10));
        reportParameters.put("razonII",new Long(9));
        reportParameters.put("razonIII",new Long(18));
        reportParameters.put("comunI",new Long(10));
        reportParameters.put("comunII",new Long(9));
        reportParameters.put("comunIII",new Long(18));
        reportParameters.put("aptI",new Long(10));
        reportParameters.put("aptII",new Long(9));
        reportParameters.put("aptIII",new Long(18));
        reportParameters.put("planI",new Long(10));
        reportParameters.put("planII",new Long(9));
        reportParameters.put("planIII",new Long(18));
        reportParameters.put("arteI",new Long(10));
        reportParameters.put("arteII",new Long(9));
        reportParameters.put("arteIII",new Long(18));
        reportParameters.put("personI",new Long(10));
        reportParameters.put("personII",new Long(9));
        reportParameters.put("personIII",new Long(18));
        reportParameters.put("educaI",new Long(10));
        reportParameters.put("educaII",new Long(9));
        reportParameters.put("educaIII",new Long(18));
        reportParameters.put("cienciaI",new Long(10));
        reportParameters.put("cienciaII",new Long(9));
        reportParameters.put("cienciaIII",new Long(18));
        reportParameters.put("religionI",new Long(10));
        reportParameters.put("religionII",new Long(9));
        reportParameters.put("religionIII",new Long(18));
        reportParameters.put("compuI",new Long(10));
        reportParameters.put("compuII",new Long(9));
        reportParameters.put("compuIII",new Long(18));
        reportParameters.put("inglesI",new Long(10));
        reportParameters.put("inglesII",new Long(9));
        reportParameters.put("inglesIII",new Long(18));
        reportParameters.put("conducI",new Long(10));
        reportParameters.put("conducII",new Long(9));
        reportParameters.put("conducIII",new Long(18));
        reportParameters.put("toeI",new Long(10));
        reportParameters.put("toeII",new Long(9));
        reportParameters.put("toeIII",new Long(10));
        
        
 
        return reportParameters;
    }
 
    public String execute() {
        try {
            System.out.println("Iniciando llamado de reporte....");
            super.prepareReportWhitoutConn();
        } catch (Exception e) {
            // make your own exception handling
             System.out.println("Error...."+e.getMessage());
            e.printStackTrace();
        }
 
        return null;
    }

    /**
    

    /**
     * @return the anio
     */
    public Anio getAnio() {
        return anio;
    }

    /**
     * @param anio the anio to set
     */
    public void setAnio(Anio anio) {
        this.anio = anio;
    }

    /**
     * @return the strDescAnio
     */
    public String getStrDescAnio() {
        return strDescAnio;
    }

    /**
     * @param strDescAnio the strDescAnio to set
     */
    public void setStrDescAnio(String strDescAnio) {
        this.strDescAnio = strDescAnio;
    }

    /**
     * @return the strAbreviaturaGrado
     */
    public String getStrAbreviaturaGrado() {
        return strAbreviaturaGrado;
    }

    /**
     * @param strAbreviaturaGrado the strAbreviaturaGrado to set
     */
    public void setStrAbreviaturaGrado(String strAbreviaturaGrado) {
        this.strAbreviaturaGrado = strAbreviaturaGrado;
    }

     public ResultSet rsNotasLibreta(){
        ResultSet rsNota=null;
         try {
             Connection conn= Database.getConnection();
             conn.setAutoCommit(false);
            CallableStatement s = conn.prepareCall("{?= call sp_nota_libreta(?,?,?)}");
            s.registerOutParameter(1, java.sql.Types.OTHER);
            s.setInt(2,1);
            s.setInt(3,1);
            s.setInt(4,5);
            s.execute();
           // rsNota=s.getResultSet();
          rsNota = (ResultSet) s.getObject(1);
          conn.close();
          return rsNota;
          
        } catch (SQLException ex) {
            System.out.println("error:" + ex.toString());
            log.error("error:::" + ex);
            
        }
        
        return null;
     }
     
      
   }
